package com.example.jack.community.view.home;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import java.lang.ref.WeakReference;

/**
 * Created by vveng on 2017/11/14 16: 29
 *
 * @mail: vvengStruggle@163.com
 */

public class HomeCunstomizeHandler extends Handler {
    WeakReference<HomeFragment1> mWeakReference; //用弱引用防止内存溢出
    private static String TAG = "HomeFragment1";
    private static final int CHANGE_ITEM = 0x001;
    public HomeCunstomizeHandler(HomeFragment1 homeFragment) {
        this.mWeakReference = new WeakReference<>(homeFragment);
    }
    @Override
    public void handleMessage(Message msg) {
        final HomeFragment1 homeFragment = mWeakReference.get();
        Log.d(TAG, "handleMessage: " + "handler is running");
                 int currentItem = homeFragment.mViewPager.getCurrentItem();
                 currentItem ++ ;
                 homeFragment.mViewPager.setCurrentItem(currentItem);
            sendEmptyMessageDelayed(0,7000);

//        if (homeFragment.isSlidingByHand) {
//            homeFragment.cnt = msg.arg1;
//            homeFragment.isSlidingByHand = false;
//            homeFragment.isSlidingAuto = true;
//            homeFragment.home_viewpager.smoothScrollToPosition(++homeFragment.cnt);
//        } else{
//            int visibility = homeFragment.home_viewpager.getVisibility();
//            if(visibility == View.GONE){ //当轮播图不可见时停止轮播
//                Log.d(TAG,homeFragment.cnt+"if"+ visibility);
//                homeFragment.home_viewpager.smoothScrollToPosition(homeFragment.cnt);
//            }else{
//                Log.d(TAG,homeFragment.cnt+"else" + visibility);
//                homeFragment.home_viewpager.smoothScrollToPosition(++homeFragment.cnt);
//            }
//        }
    }

}
